#ifndef _RAPIDFIREBUTTON
#define _RAPIDFIREBUTTON

#include "WPILib.h"
#include "GenericButton.h"

/*
 * RapidFireButton.h
 * 
 * 
 * a class which monitors a button and, when pressed, pulses from on to off
 * 
 * so you can, for example, hook it up to a trigger and a shooter,
 * and while the button is pressed the shooter fires, pauses, fires, pauses, ...
 */


class RapidFireButton : public GenericButton
{
public:
	// constructor based on a GenericButton (period defaults to 0.05)
	RapidFireButton(GenericButton *button, float period = 0.05);
	
	// set the time (in seconds) between samples
	void SetSampleRate(float period);
	
	// for how many samples should the output be on (while the button is pressed)
	void SetOnSamples(int number_of_samples);
	
	// for how many samples should the output be off (while the button is pressed)
	void SetOffSamples(int number_of_samples);
	
	// is the button on? - uses rapid fire mode
	bool Get();
	
	/*
	 * Call the Update method as a non-static method.
	 * Do fancy stuff to setup the "this" pointer
	 */
	static void CallUpdate(void *ob);
	// this function is called periodically to monitor the status of the button and act accordingly
	void Update();
	
	// enable the button (it now responds to button pushes)
	void Enable();
	// disable the button (it now ignores button pushes)
	void Disable();
	
private:
	// initialize member variables, start Notifier
	void Init(float period);
	
	GenericButton *m_button;
	Notifier *m_controlLoop;
	
	bool m_enabled;			// default false
	bool m_pressed;
	bool m_output;
	int m_on_samples;
	int m_off_samples;
	int m_count;
};


#endif
